<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>星藏检测报告审核平台</title>
    <link rel="shortcut icon" th:href="@{/logo/favicon.ico}"/>
    <!-- Custom fonts for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/vendor/fontawesome-free/css/all.min.css}"/>
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
    <!-- Custom styles for this template-->
    <link rel="stylesheet" type="text/css" th:href="@{/css/sb-admin-2.min.css}"/>

</head>

<body class="bg-gradient-primary">
<div class="container">
    <!-- Outer Row -->
    <div class="row justify-content-center">
        <div class="col-xl-10 col-lg-12 col-md-9">
            <div class="card o-hidden border-0 shadow-lg my-5">
                <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="row">
                        <div class="col-lg-6 d-none d-lg-block"><img style="width: 100%" src="/logo/logo.png" alt=""></div>
                        <div class="col-lg-6">
                            <div class="p-5">
                                <div class="text-center">
                                    <h1 class="h4 text-gray-900 mb-4">检测报告审核平台</h1>
                                </div>
                                <div class="user">
                                    <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="zn_username" required aria-describedby="emailHelp" placeholder="输入用户名">
                                    </div>
                                    <div class="form-group">
                                        <input type="password" class="form-control form-control-user" id="zn_password" required placeholder="密码">
                                    </div>
                                    <div class="form-group">
                                        <div class="custom-control custom-checkbox small">
                                            <input type="checkbox" class="custom-control-input" id="customCheck">
                                            <label class="custom-control-label" for="customCheck">记住我</label>
                                        </div>
                                    </div>
                                    <button id="login_button" class="btn btn-primary btn-user btn-block">
                                        登录
                                    </button>
                                    <hr>
                                </div>
                                <div class="text-center">
<!--                                    <a class="small" href="forgot-password.html">忘记密码?</a>-->
                                    <a class="small" href="#">忘记密码?</a>
                                </div>
                                <div class="text-center">
<!--                                    <a class="small" href="register.html">新建账号!</a>-->
                                    <a class="small" href="#">新建账号!</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Bootstrap core JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>
<!-- Core plugin JavaScript-->
<script type="text/javascript" th:src="@{/vendor/jquery-easing/jquery.easing.min.js}"></script>
<!-- Custom scripts for all pages-->
<script type="text/javascript" th:src="@{/js/sb-admin-2.min.js}"></script>
<script>
    function initView() {
        if (getCookie("cookie_account")) {
            $("#zn_username").val(getCookie("cookie_account"));
        }
        if (getCookie("cookie_password")) {
            $("#zn_password").val(getCookie("cookie_password"));
        }
        if (getCookie("rememberMe")) {
            $("#customCheck").attr("checked", getCookie("rememberMe"));
        }
        $("#zn_username").focus(function () {
            this.select();
        });
        $("#zn_password").focus(function () {
            this.select();
        });
    }
    initView();  //cookie加载 账号密码
    $("#login_button").click(function () {
        var username = $("#zn_username").val();
        var password = $("#zn_password").val();
        if(username == ""){
            alert("请输入账号")
            return false;
        }else if(password == ""){
            alert("请输入密码")
            return false;
        }
        $.ajax({
            url:"/vei/login",
            type:"post",
            contentType: "application/json;charset=utf-8",
            data:JSON.stringify({username:username,password:password}),
            dateType:"json",
            success: function (data) {
                console.log(data.code);
                if(data.code == 200){
                    //记住我
                    if ($("#customCheck").is(":checked")) {
                        setCookie("cookie_account", username);
                        setCookie("cookie_password", password);
                        setCookie("rememberMe", true);
                    } else {
                        delCookie("cookie_account");
                        delCookie("cookie_password");
                        delCookie("rememberMe");
                    }
                    //记住我 end
                    var arr = data.data.split(":");
                    localStorage.setItem("token",arr[0]);
                    console.log(arr[0]);
                    if(arr[0] == "72" || arr[0] == "73"){
                        window.location.href = "/user/submit_report2_2";
                        return;
                    }
                    switch (arr[1]) {
                        case "1":
                            window.location.href = "/user/submit_report";
                            break;
                        case "2":
                            window.location.href = "/admin/verify_report";
                            break;
                        case "3":
                            window.location.href = "/admin/audit_report";
                            break;
                        case "4":
                            window.location.href = "/admin/audit_report";
                            break;
                        case "5":
                            window.location.href = "/user/submit_report";
                            break;
                        case "6":
                            window.location.href = "/vehicle/view_all";
                            break;
                    }
                }else{
                    alert(data.message);
                }
            }
        })
    });

    function setCookie(name, value) {
        var Days = 30; //此 cookie 将被保存 30 天
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }
    /**
     * 删除cookie
     * @param name
     */
    function delCookie(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
    /**
     * 读取cookie
     * @param name
     * @returns
     */
    function getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null)
            return unescape(arr[2]);
        return null;
    }
</script>
</body>
</html>
